<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); ?>
<?php
class Baby_cabang extends CI_Controller {
    public static $link_view, $link_controller;
    function  __construct() {
        parent::__construct();
        $this->load->model('Arisan_model');
        $this->load->model('Wilayah_model');
        $this->load->model('Unit_model');
        $this->load->model('User_model');
        $this->load->model('Cabang_model');
        self::$link_view = 'admin_views/calon_manager';
        $data['link_view'] = self::$link_view;
        $this->load->helper(array('html','form', 'url','jq_plugin'));
        $this->load->library('form_validation');


    }


    var $limit = 10;
   function index($offset=''){

	$data['wilayah'] = $this->Wilayah_model->getBaby();

        $this->load->view('admin_views/wilayah/baby_cabang', $data);
    }

	function lookupCabang(){
	$keyword = $this->input->post('term');
        $data['response'] = 'false';
        $query = $this->Cabang_model->selectCabang($keyword);
        if( ! empty($query) )
        {
            $data['response'] = 'true'; 
            $data['message'] = array(); 
            foreach( $query as $row )
            {
                $data['message'][] = array( 
                                        'id'=>$row->intid_cabang,
                                        'value' => $row->strnama_cabang,
                                        ''
                                     );  
            }
        }
        if('IS_AJAX')
        {
            echo json_encode($data); 
        }
        else
        {
            $this->load->view('admin_views/autocomplete/index',$data); 
        }
	}
	function lookupCabang2(){
	$keyword = $this->input->post('term');
        $data['response'] = 'false';
        $query = $this->Cabang_model->selectCabang2($keyword);
        if( ! empty($query) )
        {
            $data['response'] = 'true';
            $data['message'] = array();
            foreach( $query as $row )
            {
                $data['message'][] = array(
                                        'id'=>$row->intid_cabang,
                                        'value' => $row->strnama_cabang,
                                        ''
                                     );
            }
        }
        if('IS_AJAX')
        {
            echo json_encode($data);
        }
        else
        {
            $this->load->view('admin_views/autocomplete/index',$data);
        }
	}

	function add()
	{
		$this->form_validation->set_rules('intid_cabang', 'Nama Cabang', 'trim|required|xss_clean');
		$this->form_validation->set_rules('intid_cabang2', 'Nama Cabang', 'trim|required|xss_clean');

		$this->form_validation->set_message('required', ' %s tidak boleh kosong !!');
			
		if ($this->form_validation->run() == FALSE)
		 {
                       $this->load->view('admin_views/wilayah/add_baby_cabang');
		}else{

                        $this->Wilayah_model->insert_baby($_POST);
			redirect('baby_cabang/index');
                }
				
	}

      function edit($intid_wilayah)
		{
			if($_POST==NULL)
			{

				$datawilayah = $this->Wilayah_model->select($intid_wilayah);
				foreach ($datawilayah as $g)
				{
					$data['intid_wilayah']	 	= $g->intid_wilayah;
					$data['strwilayah'] 		= $g->strwilayah;
				}
				$this->load->view('admin_views/wilayah/edit', $data);
			}else {
				$this->Wilayah_model->update($intid_wilayah);
				redirect('wilayah/index');
			}

		}
      function edit_baby($id)
		{
			if($_POST==NULL)
			{
			$this->load->view('admin_views/wilayah/edit_baby');
			}else {
				$this->Wilayah_model->update_baby($id);
				redirect('baby_cabang/index');
			}

		}


    function delete($id)
	{
		$this->Wilayah_model->delete_baby($id);
		redirect('baby_cabang/index');
	}
}
?>
